package com.hq.ims.home.controller;

import com.hq.ims.data.entity.Dict;
import com.hq.ims.data.service.BaseDictService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.vo.DictMapstruct;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "字典")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_PUBLIC_URL_PREFIX + "/sys/dict")
public class DictController {

    @Resource
    private BaseDictService baseDictService;

    @ApiOperation(value = "根据父ID查询字典", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getDictByParentId", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<Dict>> getDictByParentId(
            @GetJsonValue(required = false, df = "0") String parentId
    ) {
        List<Dict> list = baseDictService.getDictByParentId(parentId);
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "根据父ID查询返回树结构", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getDictTreeByParentId", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<DictMapstruct.DictTreeVo>> getDictTreeByParentId(
            @GetJsonValue(required = false, df = "0") String parentId
    ) {
        List<DictMapstruct.DictTreeVo> dictTreeVoList = baseDictService.getDictTreeByParentId(parentId);
        return ReturnVo.buildSuccess(dictTreeVoList);
    }

}
